<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>搜索结果 - GameHub</title>
    <style>
        /* 使用与主页面相同的CSS样式 */
        :root {
            --primary-color: #6c5ce7;
            --secondary-color: #a29bfe;
            --dark-color: #2d3436;
            --light-color: #f5f6fa;
            --success-color: #00b894;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background-color: var(--light-color);
            color: var(--dark-color);
        }
        
        header {
            background-color: var(--primary-color);
            color: white;
            padding: 1rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        
        .logo {
            font-size: 1.8rem;
            font-weight: bold;
        }
        
        nav ul {
            display: flex;
            list-style: none;
        }
        
        nav ul li {
            margin-left: 1.5rem;
        }
        
        nav ul li a {
            color: white;
            text-decoration: none;
            font-weight: 500;
            transition: all 0.3s ease;
        }
        
        nav ul li a:hover {
            color: var(--secondary-color);
        }
        
        .search-bar {
            display: flex;
            margin: 1rem 0;
        }
        
        .search-bar input {
            padding: 0.5rem;
            border: 1px solid #ddd;
            border-radius: 4px 0 0 4px;
            width: 300px;
        }
        
        .search-bar button {
            padding: 0.5rem 1rem;
            background-color: var(--dark-color);
            color: white;
            border: none;
            border-radius: 0 4px 4px 0;
            cursor: pointer;
        }
        
        .user-actions a {
            color: white;
            text-decoration: none;
            margin-left: 1rem;
        }
        
        /* 搜索结果页面特定样式 */
        .search-results-container {
            padding: 2rem;
            max-width: 1200px;
            margin: 0 auto;
        }
        
        .search-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 2rem;
            padding-bottom: 1rem;
            border-bottom: 1px solid #eee;
        }
        
        .search-query {
            font-size: 1.5rem;
            color: var(--primary-color);
        }
        
        .results-count {
            color: #666;
            font-size: 1rem;
        }
        
        .search-filters {
            display: flex;
            gap: 1rem;
            margin-bottom: 2rem;
        }
        
        .filter-dropdown {
            position: relative;
        }
        
        .filter-btn {
            padding: 0.5rem 1rem;
            background-color: white;
            border: 1px solid #ddd;
            border-radius: 4px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        
        .filter-options {
            position: absolute;
            top: 100%;
            left: 0;
            background-color: white;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            z-index: 10;
            display: none;
            min-width: 200px;
        }
        
        .filter-options.show {
            display: block;
        }
        
        .filter-option {
            padding: 0.8rem 1rem;
            cursor: pointer;
        }
        
        .filter-option:hover {
            background-color: #f5f6fa;
        }
        
        .no-results {
            text-align: center;
            padding: 3rem;
            color: #666;
        }
        
        .no-results h3 {
            margin-bottom: 1rem;
            font-size: 1.5rem;
        }
        
        .no-results p {
            margin-bottom: 1.5rem;
        }
        
        .btn-suggestions {
            display: flex;
            gap: 1rem;
            justify-content: center;
        }
        
        /* 游戏列表样式 - 与主页一致 */
        .game-list {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 1.5rem;
        }
        
        .game-card {
            background-color: var(--light-color);
            border-radius: 8px;
            overflow: hidden;
            transition: all 0.3s ease;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }
        
        .game-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
        
        .game-image {
            height: 200px;
            overflow: hidden;
        }
        
        .game-image img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.5s ease;
        }
        
        .game-card:hover .game-image img {
            transform: scale(1.1);
        }
        
        .game-info {
            padding: 1rem;
        }
        
        .game-title {
            font-size: 1.1rem;
            margin-bottom: 0.5rem;
            font-weight: 600;
        }
        
        .game-price {
            color: var(--primary-color);
            font-weight: bold;
            font-size: 1.2rem;
            margin-bottom: 0.5rem;
        }
        
        .game-actions {
            display: flex;
            justify-content: space-between;
            margin-top: 1rem;
        }
        
        .btn {
            padding: 0.5rem 1rem;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.3s ease;
        }
        
        .btn-primary {
            background-color: var(--primary-color);
            color: white;
        }
        
        .btn-primary:hover {
            background-color: #5649c0;
        }
        
        .btn-secondary {
            background-color: var(--dark-color);
            color: white;
        }
        
        .btn-secondary:hover {
            background-color: #1a1e1f;
        }
        
        /* 页脚样式 - 与主页一致 */
        footer {
            background-color: var(--dark-color);
            color: white;
            padding: 2rem;
            margin-top: 2rem;
        }
        
        .footer-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 2rem;
        }
        
        .footer-section h3 {
            margin-bottom: 1rem;
            font-size: 1.2rem;
        }
        
        .footer-section ul {
            list-style: none;
        }
        
        .footer-section ul li {
            margin-bottom: 0.5rem;
        }
        
        .footer-section ul li a {
            color: #ddd;
            text-decoration: none;
        }
        
        .footer-section ul li a:hover {
            color: white;
        }
        
        .copyright {
            text-align: center;
            margin-top: 2rem;
            padding-top: 1rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            header {
                flex-direction: column;
                align-items: flex-start;
            }
            
            nav ul {
                margin-top: 1rem;
            }
            
            .search-bar {
                width: 100%;
                margin: 1rem 0;
            }
            
            .search-bar input {
                width: 100%;
            }
            
            .search-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 1rem;
            }
            
            .search-filters {
                flex-wrap: wrap;
            }
            
            .game-list {
                grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            }
        }
    </style>
</head>
<body>
    <!-- 头部导航 -->
    <header>
        <div class="logo">GameHub</div>
        <nav>
            <ul>
                <li><a href="index.html">首页</a></li>
                <li><a href="#">游戏商城</a></li>
                <li><a href="#">特惠活动</a></li>
                <li><a href="#">新游预告</a></li>
                <li><a href="#">社区论坛</a></li>
            </ul>
        </nav>
        <div class="user-actions">
            <a href="#" id="login-btn">登录</a>
            <a href="#" id="register-btn">注册</a>
            <a href="cart.html"><i class="fas fa-shopping-cart"></i> 购物车</a>
        </div>
    </header>

    <!-- 搜索栏 -->
    <div class="container">
        <div class="search-bar">
            <input type="text" id="search-input" placeholder="搜索游戏名称、类型或发行商..." value="">
            <button id="search-btn"><i class="fas fa-search"></i> 搜索</button>
        </div>
    </div>

    <!-- 搜索结果内容 -->
    <div class="search-results-container">
        <div class="search-header">
            <div>
                <h2 class="search-query">搜索结果：<span id="search-query-text">赛博朋克</span></h2>
                <p class="results-count">共找到 <span id="results-count">3</span> 个结果</p>
            </div>
            <div class="search-filters">
                <div class="filter-dropdown">
                    <button class="filter-btn">排序方式 <i class="fas fa-chevron-down"></i></button>
                    <div class="filter-options" id="sort-options">
                        <div class="filter-option" data-sort="default">默认排序</div>
                        <div class="filter-option" data-sort="price-asc">价格从低到高</div>
                        <div class="filter-option" data-sort="price-desc">价格从高到低</div>
                        <div class="filter-option" data-sort="popular">人气排序</div>
                        <div class="filter-option" data-sort="newest">最新上架</div>
                    </div>
                </div>
                <div class="filter-dropdown">
                    <button class="filter-btn">价格区间 <i class="fas fa-chevron-down"></i></button>
                    <div class="filter-options" id="price-options">
                        <div class="filter-option" data-price="all">全部价格</div>
                        <div class="filter-option" data-price="0-100">¥100以下</div>
                        <div class="filter-option" data-price="100-200">¥100-200</div>
                        <div class="filter-option" data-price="200-300">¥200-300</div>
                        <div class="filter-option" data-price="300">¥300以上</div>
                    </div>
                </div>
                <div class="filter-dropdown">
                    <button class="filter-btn">游戏类型 <i class="fas fa-chevron-down"></i></button>
                    <div class="filter-options" id="category-options">
                        <div class="filter-option" data-category="all">全部类型</div>
                        <div class="filter-option" data-category="action">动作冒险</div>
                        <div class="filter-option" data-category="rpg">角色扮演</div>
                        <div class="filter-option" data-category="strategy">策略模拟</div>
                        <div class="filter-option" data-category="sports">体育竞技</div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 搜索结果列表 -->
        <div class="game-list" id="search-results-list">
            <!-- 游戏卡片1 -->
            <div class="game-card" data-id="game-5" data-price="299" data-category="rpg" data-popularity="4.9" data-date="2023-05-15">
                <div class="game-image">
                    <img src="images/5.png" alt="赛博朋克2077">
                </div>
                <div class="game-info">
                    <h3 class="game-title">赛博朋克2077</h3>
                    <div class="game-price">¥299</div>
                    <div class="game-rating">★★★★★ (4.9)</div>
                    <div class="game-actions">
                        <button class="btn btn-primary">加入购物车</button>
                        <button class="btn btn-secondary">查看详情</button>
                    </div>
                </div>
            </div>
            
            <!-- 游戏卡片2 -->
            <div class="game-card" data-id="game-1" data-price="199" data-category="rpg" data-popularity="4.5" data-date="2023-03-10">
                <div class="game-image">
                    <img src="images/1.png" alt="幻想世界：失落王国">
                </div>
                <div class="game-info">
                    <h3 class="game-title">幻想世界：失落王国</h3>
                    <div class="game-price">¥199</div>
                    <div class="game-rating">★★★★☆ (4.5)</div>
                    <div class="game-actions">
                        <button class="btn btn-primary">加入购物车</button>
                        <button class="btn btn-secondary">查看详情</button>
                    </div>
                </div>
            </div>
            
            <!-- 游戏卡片3 -->
            <div class="game-card" data-id="game-7" data-price="279" data-category="rpg" data-popularity="4.7" data-date="2023-06-20">
                <div class="game-image">
                    <img src="images/7.png" alt="最终幻想XVI">
                </div>
                <div class="game-info">
                    <h3 class="game-title">最终幻想XVI</h3>
                    <div class="game-price">¥279</div>
                    <div class="game-rating">★★★★☆ (4.7)</div>
                    <div class="game-actions">
                        <button class="btn btn-primary">加入购物车</button>
                        <button class="btn btn-secondary">查看详情</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- 无结果时的显示 -->
        <div class="no-results" id="no-results" style="display: none;">
            <h3>没有找到匹配的游戏</h3>
            <p>我们无法找到与"<span id="no-results-query"></span>"相关的游戏，请尝试其他关键词。</p>
            <div class="btn-suggestions">
                <button class="btn btn-primary">查看热门游戏</button>
                <button class="btn btn-secondary">浏览所有游戏</button>
            </div>
        </div>
    </div>

    <!-- 页脚 -->
    <footer>
        <div class="footer-content">
            <div class="footer-section">
                <h3>关于我们</h3>
                <ul>
                    <li><a href="#">公司简介</a></li>
                    <li><a href="#">团队介绍</a></li>
                    <li><a href="#">联系方式</a></li>
                    <li><a href="#">加入我们</a></li>
                </ul>
            </div>
            <div class="footer-section">
                <h3>客户服务</h3>
                <ul>
                    <li><a href="#">帮助中心</a></li>
                    <li><a href="#">支付方式</a></li>
                    <li><a href="#">配送方式</a></li>
                    <li><a href="#">退换政策</a></li>
                </ul>
            </div>
            <div class="footer-section">
                <h3>法律信息</h3>
                <ul>
                    <li><a href="#">用户协议</a></li>
                    <li><a href="#">隐私政策</a></li>
                    <li><a href="#">版权声明</a></li>
                    <li><a href="#">知识产权</a></li>
                </ul>
            </div>
            <div class="footer-section">
                <h3>关注我们</h3>
                <ul>
                    <li><a href="#">微信公众号</a></li>
                    <li><a href="#">微博</a></li>
                    <li><a href="#">B站</a></li>
                    <li><a href="#">抖音</a></li>
                </ul>
            </div>
        </div>
        <div class="copyright">
            <p>© 2023 GameHub游戏购物平台. 版权所有. 学号：123456 姓名：张三</p>
        </div>
    </footer>

    <!-- JavaScript -->
    <script>
        // 从URL获取搜索查询参数
        function getQueryParam(name) {
            const urlParams = new URLSearchParams(window.location.search);
            return urlParams.get(name);
        }
        
        // 初始化页面
        document.addEventListener('DOMContentLoaded', function() {
            const searchInput = document.getElementById('search-input');
            const searchBtn = document.getElementById('search-btn');
            const searchQueryText = document.getElementById('search-query-text');
            const resultsCount = document.getElementById('results-count');
            const searchResultsList = document.getElementById('search-results-list');
            const noResultsDiv = document.getElementById('no-results');
            const noResultsQuery = document.getElementById('no-results-query');
            
            // 获取搜索查询
            const query = getQueryParam('q');
            if (query) {
                searchInput.value = query;
                searchQueryText.textContent = query;
                
                // 模拟搜索 - 实际项目中应该从服务器获取结果
                simulateSearch(query);
            }
            
            // 搜索按钮点击事件
            searchBtn.addEventListener('click', function() {
                const query = searchInput.value.trim();
                if (query) {
                    // 实际项目中应该跳转到搜索结果页
                    window.location.href = `search.html?q=${encodeURIComponent(query)}`;
                }
            });
            
            // 回车键搜索
            searchInput.addEventListener('keypress', function(e) {
                if (e.key === 'Enter') {
                    searchBtn.click();
                }
            });
            
            // 筛选功能
            setupFilterDropdowns();
            
            // 模拟搜索函数 - 实际项目中应该从服务器获取结果
            function simulateSearch(query) {
                // 这里应该有实际的搜索逻辑
                // 这里我们只是模拟根据查询显示/隐藏游戏卡片
                const gameCards = document.querySelectorAll('.game-card');
                let visibleCount = 0;
                
                gameCards.forEach(card => {
                    const title = card.querySelector('.game-title').textContent.toLowerCase();
                    if (title.includes(query.toLowerCase())) {
                        card.style.display = 'block';
                        visibleCount++;
                    } else {
                        card.style.display = 'none';
                    }
                });
                
                // 更新结果计数
                resultsCount.textContent = visibleCount;
                
                // 显示无结果信息或结果列表
                if (visibleCount === 0) {
                    searchResultsList.style.display = 'none';
                    noResultsDiv.style.display = 'block';
                    noResultsQuery.textContent = query;
                } else {
                    searchResultsList.style.display = 'grid';
                    noResultsDiv.style.display = 'none';
                }
            }
            
            // 设置筛选下拉菜单
            function setupFilterDropdowns() {
                const filterBtns = document.querySelectorAll('.filter-btn');
                const filterOptions = document.querySelectorAll('.filter-options');
                
                // 点击筛选按钮
                filterBtns.forEach(btn => {
                    btn.addEventListener('click', function(e) {
                        e.stopPropagation();
                        const options = this.nextElementSibling;
                        
                        // 关闭其他打开的选项
                        filterOptions.forEach(opt => {
                            if (opt !== options) {
                                opt.classList.remove('show');
                            }
                        });
                        
                        // 切换当前选项
                        options.classList.toggle('show');
                    });
                });
                
                // 点击选项
                document.querySelectorAll('.filter-option').forEach(option => {
                    option.addEventListener('click', function() {
                        const dropdown = this.closest('.filter-options');
                        const filterBtn = dropdown.previousElementSibling;
                        
                        // 更新按钮文本
                        filterBtn.innerHTML = `${this.textContent} <i class="fas fa-chevron-down"></i>`;
                        
                        // 关闭下拉菜单
                        dropdown.classList.remove('show');
                        
                        // 应用筛选 - 实际项目中应该重新从服务器获取筛选后的结果
                        applyFilters();
                    });
                });
                
                // 点击页面其他区域关闭下拉菜单
                document.addEventListener('click', function() {
                    filterOptions.forEach(opt => {
                        opt.classList.remove('show');
                    });
                });
            }
            
            // 应用筛选条件 - 实际项目中应该从服务器获取筛选后的结果
            function applyFilters() {
                // 获取当前筛选条件
                const sortOption = document.querySelector('#sort-options .filter-option.active')?.dataset.sort || 'default';
                const priceOption = document.querySelector('#price-options .filter-option.active')?.dataset.price || 'all';
                const categoryOption = document.querySelector('#category-options .filter-option.active')?.dataset.category || 'all';
                
                // 这里应该有实际的筛选逻辑
                console.log('应用筛选:', { sortOption, priceOption, categoryOption });
                
                // 模拟筛选 - 实际项目中应该从服务器获取结果
                const gameCards = Array.from(document.querySelectorAll('.game-card'));
                
                // 价格筛选
                if (priceOption !== 'all') {
                    const [min, max] = priceOption.split('-').map(Number);
                    gameCards.forEach(card => {
                        const price = parseInt(card.dataset.price);
                        if ((max && (price < min || price > max)) || (!max && price < min)) {
                            card.style.display = 'none';
                        } else {
                            card.style.display = 'block';
                        }
                    });
                }
                
                // 类型筛选
                if (categoryOption !== 'all') {
                    gameCards.forEach(card => {
                        if (card.dataset.category !== categoryOption) {
                            card.style.display = 'none';
                        } else {
                            card.style.display = 'block';
                        }
                    });
                }
                
                // 排序
                if (sortOption !== 'default') {
                    gameCards.sort((a, b) => {
                        switch (sortOption) {
                            case 'price-asc':
                                return parseInt(a.dataset.price) - parseInt(b.dataset.price);
                            case 'price-desc':
                                return parseInt(b.dataset.price) - parseInt(a.dataset.price);
                            case 'popular':
                                return parseFloat(b.dataset.popularity) - parseFloat(a.dataset.popularity);
                            case 'newest':
                                return new Date(b.dataset.date) - new Date(a.dataset.date);
                            default:
                                return 0;
                        }
                    });
                    
                    // 重新排列DOM元素
                    const container = document.getElementById('search-results-list');
                    gameCards.forEach(card => {
                        container.appendChild(card);
                    });
                }
                
                // 更新可见结果计数
                const visibleCount = document.querySelectorAll('.game-card[style="display: block"]').length;
                resultsCount.textContent = visibleCount;
                
                // 显示无结果信息或结果列表
                if (visibleCount === 0) {
                    searchResultsList.style.display = 'none';
                    noResultsDiv.style.display = 'block';
                    noResultsQuery.textContent = searchInput.value;
                } else {
                    searchResultsList.style.display = 'grid';
                    noResultsDiv.style.display = 'none';
                }
            }
        });
    </script>
</body>
</html>